package com.rwx.myjetpack

import java.util.*


/**
 * Created by LH on 2023-05-25.
 * Time: 2023-05-25  11:21
 */
class UserModel {

    companion object{
        const val STATE_LOADING=0
        const val STATE_SUCCESS=1
        const val STATE_FAILED=2
    }

    val api by lazy { API() }

    private val random= Random()


    fun doLogin(account: String, password: String,block:(Int)->Unit) {

        block.invoke(STATE_LOADING)



        val randomValue=random.nextInt(30)
        if(randomValue %2  ==0){
            block.invoke(STATE_SUCCESS)
        }else{
            block.invoke(STATE_FAILED)
        }

    }

    fun checkUserState(account:String,block:(Int)-> Unit){
        block.invoke(random.nextInt(2))
    }

    interface OnDologinStateChange{
        fun onLoading()
        fun onLoginSuccess()
        fun onLoginFailed()
    }
}